//
//  SHMainViewController.swift
//  三期微博1
//
//  Created by TownFish on 16/7/19.
//  Copyright © 2016年 TownFish. All rights reserved.
//

import UIKit

class SHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //代码抽取了,这些不需要了
//        let homeVc = SHHomeViewController()
//        //设置导航title
//        homeVc.navigationItem.title = "首页"
//        //设置tabBar title
//        homeVc.tabBarItem.title = "首页"
//        //设置图片
//        homeVc.tabBarItem.image = UIImage(named: "tabbar_home")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        //修改渲染方式
//        homeVc.tabBarItem.selectedImage = UIImage(named: "tabbar_home_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        // 设置颜色
//        homeVc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加子控制器
//        addChildViewController(UINavigationController(rootViewController: homeVc))
        addChildViewController(SHHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(SHMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(SHDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(SHProfileViewController(), title: "我", imgName: "tabbar_profile")
        
    }
    
    func addChildViewController(vc: UIViewController,title: String, imgName: String) {
//        //设置导航title
//        vc.navigationItem.title = title
//        //设置tabBar title
//        vc.tabBarItem.title = title
        //由上面合并后
        vc.title = title
        
        
        //设置图片
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //修改渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        // 设置颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
    

}
